QuickOPC User's Guide and Reference
Examples - OPC Unified Architecture - Read namespace array

.NET

// This example shows how to read value of server's NamespaceArray, and display the namespace URIs in it.

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace.Standard;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class ReadValue
    {
        public static void NamespaceArray()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object
            var client = new EasyUAClient();

            // Perform the operation: Obtain value of a node
            object value;
            try
            {
                value = client.ReadValue(endpointDescriptor, UAVariableIds.Server_NamespaceArray);  // i=2255
            }
            catch (UAException uaException)
            {
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException().Message);
                return;
            }

            if (!(value is string[] arrayValue))
            {
                Console.WriteLine("*** Not a string array");
                return;
            }

            // Display results
            for (int i = 0; i < arrayValue.Length; i++)
                Console.WriteLine($"{i}: {arrayValue[i]}");
        }


        // Example output:
        //
        //0: http://opcfoundation.org/UA/
        //1: urn:DEMO-5:UA Sample Server
        //2: http://test.org/UA/Data/
        //3: http://test.org/UA/Data//Instance
        //4: http://opcfoundation.org/UA/Boiler/
        //5: http://opcfoundation.org/UA/Boiler//Instance
        //6: http://opcfoundation.org/UA/Diagnostics
        //7: http://samples.org/UA/memorybuffer
        //8: http://samples.org/UA/memorybuffer/Instance
    }
}
# This example shows how to read value of server's NamespaceArray, and display the namespace URIs in it.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System import *
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.AddressSpace.Standard import *
from OpcLabs.EasyOpc.UA.OperationModel import *


endpointDescriptor = UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer')
# or 'http://opcua.demo-this.com:51211/UA/SampleServer' (currently not supported)
# or 'https://opcua.demo-this.com:51212/UA/SampleServer/'

# Instantiate the client object.
client = EasyUAClient()

# Perform the operation: Obtain value of a node.
try:
    value = IEasyUAClientExtension.ReadValue(client,
                                             endpointDescriptor,
                                             UANodeDescriptor(UAVariableIds.Server_NamespaceArray)) # i=2255
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

if not isinstance(value, Array):
    print('*** Not an array')
    exit()
arrayValue = value

# Display results.
for i, element in enumerate(arrayValue):
    print(i, ': ', element, sep='')

print()
print('Finished.')

COM

Rem This example shows how to read value of server's NamespaceArray, and display the namespace URIs in it.

Option Explicit

Const endpointDescriptorUrlString = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Perform the operation
On Error Resume Next
Dim value: value = Client.ReadValue(endpointDescriptorUrlString, "i=2255")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Work around the fact that elements of object arrays returned cannot be retrieved in VBScript directly.
Dim ElasticVector: Set ElasticVector = CreateObject("OpcLabs.BaseLib.Collections.ElasticVector")
ElasticVector.Assign(value)

' Display results
Dim i: For i = ElasticVector.LowerBound To ElasticVector.UpperBound
    WScript.Echo i & ": " & ElasticVector(i)
Next

' Example output:
'
'0: http://opcfoundation.org/UA/
'1: urn:DEMO-5:UA Sample Server
'2: http://test.org/UA/Data/
'3: http://test.org/UA/Data//Instance
'4: http://opcfoundation.org/UA/Boiler/
'5: http://opcfoundation.org/UA/Boiler//Instance
'6: http://opcfoundation.org/UA/Diagnostics
'7: http://samples.org/UA/memorybuffer
'8: http://samples.org/UA/memorybuffer/Instance